package com.qdu.study_app.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.qdu.study_app.R;
import com.qdu.study_app.bean.Notes;
import com.qdu.study_app.utils.MyToast;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class Activity_pub_message extends AppCompatActivity {

    private EditText msg_title;
    private EditText msg_content;
    private Button pub_btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pub_message);
        init();
    }
    private void init(){
        msg_content = findViewById(R.id.pub_msg_content);
        msg_title = findViewById(R.id.pub_msg_title);
        pub_btn = findViewById(R.id.pub_btn);
        pub_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(msg_content.getText() == null){
                    Toast.makeText(Activity_pub_message.this,"发布内容不为空",Toast.LENGTH_LONG);
                    return;
                }
                if(msg_title.getText() == null){
                    Toast.makeText(Activity_pub_message.this,"标题不为空",Toast.LENGTH_LONG);
                    return;
                }
                Notes article = new Notes();
                article.setUser_id(BmobUser.getCurrentUser().getObjectId());
                article.setTitle(msg_title.getText().toString());
                article.setContent(msg_content.getText().toString());
                article.save(new SaveListener<String>() {
                    @Override
                    public void done(String s, BmobException e) {
                        if(e == null){
                            System.out.println("打卡成功：+++++++++++++++++");
                            MyToast.showToast(Activity_pub_message.this,"评论成功",Toast.LENGTH_LONG);
                            finish();
                        }
                    }
                });
            }
        });
    }
}